<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>第二十四章：SpringBoot项目整合JPA多数据源配置 | 恒宇少年De成长之路</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="为什么要选择在项目配置多数据源呢？ 多数据源设计一般应用到中大型的项目中，项目关联的业务性比较复杂，使用的数据库比较分散。我们使用多数据源的目的也有很多，比如：分布式数据库读写分离、集成不同数据库等。不管初衷是什么也都是为了提高项目的可维护性、稳定性、响应速度。我们本章来讲解下如何使用SpringDataJpa来让SpringBoot项目集成多个不同数据库的数据源。">
<meta name="keywords" content="SpringBoot">
<meta property="og:type" content="article">
<meta property="og:title" content="第二十四章：SpringBoot项目整合JPA多数据源配置">
<meta property="og:url" content="http://blog.yuqiyu.com/spring-boot-chapter-24/index.html">
<meta property="og:site_name" content="恒宇少年De成长之路">
<meta property="og:description" content="为什么要选择在项目配置多数据源呢？ 多数据源设计一般应用到中大型的项目中，项目关联的业务性比较复杂，使用的数据库比较分散。我们使用多数据源的目的也有很多，比如：分布式数据库读写分离、集成不同数据库等。不管初衷是什么也都是为了提高项目的可维护性、稳定性、响应速度。我们本章来讲解下如何使用SpringDataJpa来让SpringBoot项目集成多个不同数据库的数据源。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-d4cedd6f0fdceb48.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-4b746eac12132f93.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-ef2363fa0ad9f5b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-af69bd6feb11e4df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-ece8dcf63bcd5b5c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-8ccdcbfd249b4237.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-e9b5eaa8e5e8cda5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-8d81f783c7842589.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-b624b0a5e55d31aa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-325ddb388227b48a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-11b7e7c9a495c929.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-e160ce837e8d6317.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-2d18830ae6b6e010.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-49e3750b40e680f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-5c69ba472a9b21a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-67da21e684d11110.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-20c3131715dfe3fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-2f7884d7d19a9709.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-2e3ece62d204b1cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-02-21T07:47:37.803Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="第二十四章：SpringBoot项目整合JPA多数据源配置">
<meta name="twitter:description" content="为什么要选择在项目配置多数据源呢？ 多数据源设计一般应用到中大型的项目中，项目关联的业务性比较复杂，使用的数据库比较分散。我们使用多数据源的目的也有很多，比如：分布式数据库读写分离、集成不同数据库等。不管初衷是什么也都是为了提高项目的可维护性、稳定性、响应速度。我们本章来讲解下如何使用SpringDataJpa来让SpringBoot项目集成多个不同数据库的数据源。">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/4461954-d4cedd6f0fdceb48.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
    

    
        <link rel="alternate" href="/" title="恒宇少年De成长之路" type="application/atom+xml" />
    

    

    <link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/css/style.css">

    <script src="/libs/jquery/2.1.3/jquery.min.js"></script>
    
    
        <link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/" id="logo">
                <i class="logo"></i>
                <span class="site-title">恒宇少年De成长之路</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/.">首页</a>
                
                    <a class="main-nav-link" href="/archives">时间轴</a>
                
                    <a class="main-nav-link" href="/categories">文章专题</a>
                
                    <a class="main-nav-link" href="/tags">标签云</a>
                
                    <a class="main-nav-link" href="/about">关于我</a>
                
            </nav>
            
                
                <nav id="sub-nav">
                    <div class="profile" id="profile-nav">
                        <a id="profile-anchor" href="javascript:;">
                            <img class="avatar" src="/css/images/avatar.png" />
                            <i class="fa fa-caret-down"></i>
                        </a>
                    </div>
                </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <!--button type="submit" class="search-form-submit"></button-->
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td ><a  class="main-nav-link" href="/.">首页</a></td>
                
                    <td ><a  class="main-nav-link" href="/archives">时间轴</a></td>
                
                    <td ><a  class="main-nav-link" href="/categories">文章专题</a></td>
                
                    <td ><a  class="main-nav-link" href="/tags">标签云</a></td>
                
                    <td ><a  class="main-nav-link" href="/about">关于我</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
                

<aside id="profile">
    <div class="inner profile-inner">
        <div class="base-info profile-block">
            <img id="avatar" src="/css/images/avatar.png" />
            <h2 id="name">恒宇少年</h2>
            <h3 id="title">Java软件工程师 &amp; 程序猿</h3>
            <span id="location"><i class="fa fa-map-marker"></i>山东, 济南</span>
            <a id="follow" target="_blank" href="https://www.jianshu.com/u/092df3f77bca">关注我</a>
        </div>
        <div class="article-info profile-block">
            <div class="article-info-block">
                43
                <span>文章</span>
            </div>
            <div class="article-info-block">
                2
                <span>标签</span>
            </div>
        </div>
        
        <div class="profile-block social-links">
            <table>
                <tr>
                    
                    
                    <td>
                        <a href="http://github.com/ppoffice/hexo-theme-icarus" target="_blank" title="github" class=tooltip>
                            <i class="fa fa-github"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="twitter" class=tooltip>
                            <i class="fa fa-twitter"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="facebook" class=tooltip>
                            <i class="fa fa-facebook"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="dribbble" class=tooltip>
                            <i class="fa fa-dribbble"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="rss" class=tooltip>
                            <i class="fa fa-rss"></i>
                        </a>
                    </td>
                    
                </tr>
            </table>
        </div>
        
    </div>
</aside>

            
            <section id="main"><article id="post-spring-boot-chapter-24" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
            第二十四章：SpringBoot项目整合JPA多数据源配置
        </h1>
    

                
                    <div class="article-meta">
                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/spring-boot-chapter-24/">
            <time datetime="2017-05-29T16:00:00.000Z" itemprop="datePublished">2017-05-30</time>
        </a>
    </div>


                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/tags/SpringBoot/">SpringBoot</a>
    </div>

                    </div>
                
            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
            
            <p>为什么要选择在项目配置多数据源呢？</p>
<p>多数据源设计一般应用到中大型的项目中，项目关联的业务性比较复杂，使用的数据库比较分散。我们使用多数据源的目的也有很多，比如：分布式数据库读写分离、集成不同数据库等。不管初衷是什么也都是为了提高项目的可维护性、稳定性、响应速度。我们本章来讲解下如何使用SpringDataJpa来让SpringBoot项目集成多个不同数据库的数据源。<br><a id="more"></a></p>
<h1 id="本章目标"><a href="#本章目标" class="headerlink" title="本章目标"></a>本章目标</h1><p>基于SpringBoot项目整合SpringDataJpa完成多数据源根据包名自动切换。</p>
<h1 id="构建项目"><a href="#构建项目" class="headerlink" title="构建项目"></a>构建项目</h1><p>我们使用IDEA工具创建一个SpringBoot项目，并添加JPA、Web、FastJson、Druid等依赖，pom.xml如下图1所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-d4cedd6f0fdceb48.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图1"></p>
<h2 id="创建数据库"><a href="#创建数据库" class="headerlink" title="创建数据库"></a>创建数据库</h2><p>在正式编写项目之前，我们首先创建两个数据库（test、books）test数据库内包含了一张数据表t_user，books数据库内包含了一张数据库book《表结构在项目源码resources目录下》</p>
<p>t_user表结构如下图2所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-4b746eac12132f93.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图2"></p>
<p>book表结构如下图3所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-ef2363fa0ad9f5b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图3"></p>
<h2 id="编写application-yml配置文件"><a href="#编写application-yml配置文件" class="headerlink" title="编写application.yml配置文件"></a>编写application.yml配置文件</h2><p>在我们之前单数据源单数据库的示例中我们的配置都是比较简单的，下面我们来看下我们多数据源的配置</p>
<p>用户数据库数据源配置如下图4所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-af69bd6feb11e4df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图4"></p>
<p>书籍数据库数据源配置如下图5所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-ece8dcf63bcd5b5c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图5"></p>
<p>可以看到上面两个数据源命名时都有前缀，分别是user、book。这个是我们配置时必要的属性，下面我们就来编写数据库源的映射配置类。</p>
<h2 id="DataSourceConfigurer"><a href="#DataSourceConfigurer" class="headerlink" title="DataSourceConfigurer"></a>DataSourceConfigurer</h2><p>我们自定义一个数据源配置类DataSourceConfigurer，在类内对应声明两个数据源的Bean对象，以及使用application.yml配置文件内的前缀属性配置，如下图6所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-8ccdcbfd249b4237.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图6"></p>
<pre><code>上图6内我们对应两个数据库分别定义了两个数据源，userDataSource、bookDataSource。
使用@Qualifier注解并且设置内容，是为了防止注入时冲突问题。
userDataSource数据源配置使用了application.yml文件中spring.datasource.user前缀的配置，而bookDataSource则是配置使用了spring.datasource.book前缀的配置。
</code></pre><h4 id="Primary"><a href="#Primary" class="headerlink" title="@Primary"></a>@Primary</h4><p>@Primary配置了数据源为主数据源，当没有配置自动切换的package时默认使用该数据源进行数据处理操作。</p>
<p>数据源的声明我们已经创建完成，下面我们来详细的实现对应的数据源。</p>
<h2 id="BookDataSourceConfigurer"><a href="#BookDataSourceConfigurer" class="headerlink" title="BookDataSourceConfigurer"></a>BookDataSourceConfigurer</h2><p>bookDataSourceConfigurer配置文件类是详细实现了DataSourceConfigurer类中声明的bookDataSource，实现类中大致分为了如下及部分：</p>
<h4 id="配置EntityManager"><a href="#配置EntityManager" class="headerlink" title="配置EntityManager"></a>配置EntityManager</h4><p>配置让SpringDataJpa管理实体，根据EntityManagerFactory工厂的参数构建出EntityManager，如下图7所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-e9b5eaa8e5e8cda5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图7"></p>
<h4 id="配置TransactionManager"><a href="#配置TransactionManager" class="headerlink" title="配置TransactionManager"></a>配置TransactionManager</h4><p>根据EntityManagerFactory创建事务Manager，让事务应用到实体工厂内，如下图8所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-8d81f783c7842589.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图8"></p>
<blockquote>
<p>因为DataSource的声明跟实体管理器、事务管理器是分离的所以在上图7、图8内仍然需要使用@Primary注解来配置主实体管理器、主事务管理器。</p>
</blockquote>
<p>类内的配置已经添加完成，现在我们需要指定BookDataSourceConfiguer来使用对应的配置，如下图9所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-b624b0a5e55d31aa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图9"></p>
<p>我们在类上添加开启了事务配置以及启用了SpringDataJpa的配置参数，设置事务、实体管理器、数据源所应用到的包，当使用该包下的实体以及数据接口时就会自动调用bookDataSource来处理数据。userDataSource的实现跟bookDataSource的实现几乎一样，只是少了@Primart注解以及修改对应的参数等，如下图10所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-325ddb388227b48a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图10"></p>
<p>userDataSource事务配置如下图11所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-11b7e7c9a495c929.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图11"></p>
<h2 id="查询书籍列表接口"><a href="#查询书籍列表接口" class="headerlink" title="查询书籍列表接口"></a>查询书籍列表接口</h2><p>我们来编写查询书籍列表的接口，创建对应的package，com.yuqiyu.chapter24.book，创建controller.BookController控制器如下图12所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-e160ce837e8d6317.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图12"></p>
<p>上图12中注入了BookJPA，调用了jpa内部的findAll方法来读取全部数据列表，并通过@RestController注解作用返回Json字符串。</p>
<p>创建jpa.BookJPA数据接口，如下图13所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-2d18830ae6b6e010.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图13"></p>
<p>可以看到BookJPA继承了BaseDAO父泛型接口，BaseDAO接口内统一继承了JpaRepository、JpaSpecificationExecutor等公用接口，子接口只需要继承BaseDAO就可以拥有SpringDataJPA内的内置方法，BaseDAO源码如下图14所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-49e3750b40e680f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图14"></p>
<h1 id="查询用户列表接口"><a href="#查询用户列表接口" class="headerlink" title="查询用户列表接口"></a>查询用户列表接口</h1><p>跟上面书籍列表接口一样，我们先来创建对应的package,com.yuqiyu.chapter24.user，创建用户控制器controller.UserController，如下图15所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-5c69ba472a9b21a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图15"></p>
<p>上图15内引用的userJPA也是跟bookJPA一样，继承了BaseDAO泛型接口，这里就不做出讲解了。</p>
<h1 id="运行测试"><a href="#运行测试" class="headerlink" title="运行测试"></a>运行测试</h1><p>上面步骤我们编码已经完成，下面我们开启项目来测试下数据是否是对应不用的数据库获取的，运行项目控制台输出内容如下图16所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-67da21e684d11110.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图16"></p>
<p>上图16内可以看到项目启动时加载了我们配置的两个数据源，这个name的配置对应数据源实现类内。下面我们来访问下用户列表：<a href="http://127.0.0.1:8080/user/list" target="_blank" rel="noopener">127.0.0.1:8080/user/list</a>，界面输出内容如下图17所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-20c3131715dfe3fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图17"></p>
<p>可以看到我们成功的读取到了test数据库内的t_user表内的数据。我们下面再来访问下书籍列表：<a href="http://127.0.0.1:8080/book/list" target="_blank" rel="noopener">127.0.0.1:8080/book/list</a>，界面输出内容如下图18所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-2f7884d7d19a9709.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图18"></p>
<p>我们同样成功的获取到了books数据库book表内的数据，证明我们配置的多数据源成功的自动切换并可以处理数据逻辑。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>本章主要讲解了如果基于SpringBoot项目使用SpringDataJPA自动根据package名称切换使用不同的数据源。</p>
<p>本章内容已经更新到码云：</p>
<p>SpringBoot配套源码地址：<a href="https://gitee.com/hengboy/spring-boot-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-boot-chapter</a></p>
<p>SpringCloud配套源码地址：<a href="https://gitee.com/hengboy/spring-cloud-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-cloud-chapter</a></p>
<p>SpringBoot相关系列文章请访问：<a href="http://www.jianshu.com/p/9a08417e4e84" target="_blank" rel="noopener">目录：SpringBoot学习目录</a></p>
<p>QueryDSL相关系列文章请访问：<a href="http://www.jianshu.com/p/99a5ec5c3bd5" target="_blank" rel="noopener">QueryDSL通用查询框架学习目录</a></p>
<p>SpringDataJPA相关系列文章请访问：<a href="http://www.jianshu.com/p/615ed9c1fe84" target="_blank" rel="noopener">目录：SpringDataJPA学习目录</a></p>
<p>SpringBoot相关文章请访问：<a href="http://www.jianshu.com/p/9a08417e4e84" target="_blank" rel="noopener">目录：SpringBoot学习目录</a>，感谢阅读！</p>
<p>欢迎加入QQ技术交流群，共同进步。<br><img src="http://upload-images.jianshu.io/upload_images/4461954-2e3ece62d204b1cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="QQ技术交流群"></p>

        
        </div>
        <footer class="article-footer">
            <div class="share-container">


    <div class="bdsharebuttonbox">
    <a href="#" class="bds_more" data-cmd="more">分享到：</a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>
    <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>
    <a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>
</div>
<script>
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
</script>
<style>
    .bdshare_popup_box {
        border-radius: 4px;
        border: #e1e1e1 solid 1px;
    }
    .bdshare-button-style0-16 a,
    .bdshare-button-style0-16 .bds_more {
        padding-left: 20px;
        margin: 6px 10px 6px 0;
    }
    .bdshare_dialog_list a,
    .bdshare_popup_list a,
    .bdshare_popup_bottom a {
        font-family: 'Microsoft Yahei';
    }
    .bdshare_popup_top {
        display: none;
    }
    .bdshare_popup_bottom {
        height: auto;
        padding: 5px;
    }
</style>


</div>

            
    

        </footer>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/spring-boot-chapter-25/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    第二十五章：SpringBoot添加支持CORS跨域访问
                
            </div>
        </a>
    
    
        <a href="/spring-boot-chapter-23/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">第二十三章：SpringBoot项目多模块打包与部署</div>
        </a>
    
</nav>


    
</article>


    
    

</section>
            
			
				
<aside id="sidebar">
   
        
    <div class="widget-wrap">
        <h3 class="widget-title">最新文章</h3>
        <div class="widget">
            <ul id="recent-post" class="no-thumbnail">
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-52/" class="title">第五十二章：基于SpringBoot2使用Rest访问MongoDB数据</a></p>
                            <p class="item-date"><time datetime="2018-04-21T16:00:00.000Z" itemprop="datePublished">2018-04-22</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-51/" class="title">第五十一章：基于SpringBoot2 &amp; MongoDB完成自动化集成</a></p>
                            <p class="item-date"><time datetime="2018-04-15T16:00:00.000Z" itemprop="datePublished">2018-04-16</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-50/" class="title">第五十章：SpringBoot2.0新特性 - 岂止至今最简单redis缓存集成</a></p>
                            <p class="item-date"><time datetime="2018-04-14T16:00:00.000Z" itemprop="datePublished">2018-04-15</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-49/" class="title">第四十九章：SpringBoot2.0新特性 - 你get到WebMvcConfigurer两种配置方式了吗？</a></p>
                            <p class="item-date"><time datetime="2018-03-16T16:00:00.000Z" itemprop="datePublished">2018-03-17</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-48/" class="title">第四十八章：SpringBoot2.0新特性 - RabbitMQ信任package设置</a></p>
                            <p class="item-date"><time datetime="2018-03-12T16:00:00.000Z" itemprop="datePublished">2018-03-13</time></p>
                        </div>
                    </li>
                
            </ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/QueryDSL-核心技术/">QueryDSL 核心技术</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a><span class="category-list-count">36</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">归档</h3>
        <div class="widget">
            <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">四月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">5</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签</h3>
        <div class="widget">
            <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/QueryDSL/">QueryDSL</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SpringBoot/">SpringBoot</a><span class="tag-list-count">43</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签云</h3>
        <div class="widget tagcloud">
            <a href="/tags/QueryDSL/" style="font-size: 10px;">QueryDSL</a> <a href="/tags/SpringBoot/" style="font-size: 20px;">SpringBoot</a>
        </div>
    </div>

    
        
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">链接</h3>
        <div class="widget">
            <ul>
                
                    <li>
     				<a href="http://hexo.io" target="_blank">Hexo</a>
					</li>
                
            </ul>
        </div>
    </div>


    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>

				
        </div>
        <!--引入不蒜子-->
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            <span  id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
            &copy; 2017 - 2018 恒宇少年 - 版权所有<br>
        </div>
    </div>
</footer>

        


    
        <script src="/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    



<!-- Custom Scripts -->
<script src="/js/main.js"></script>

    </div>
</body>
</html>